﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="gridPanel" style="height:100%;">
    <div id="toolbar" style="padding:2px 5px;">
        <div class="dcui-btn-area">
            <a href="#" id="NF-add" authorize="yes" class="dcui-btn dcui-btn-green"   onclick="btn_add()"><i class="fa fa-plus"></i>新建员工</a>
            <a href="#" id="NF-delete" authorize="yes" class="dcui-btn dcui-btn-red"   onclick="btn_delete()"><i class="fa fa-trash"></i>删除员工</a>
            <a href="#" id="NF-edit" authorize="yes" class="dcui-btn dcui-btn-blue"   onclick="btn_edit()"><i class="fa fa-pencil"></i>修改员工</a>
            <a href="#" id="NF-details" authorize="yes" class="dcui-btn dcui-btn-purple" onclick="btn_details()"><i class="fa fa-eye"></i>查看员工</a>
            <a href="#" id="NF-update" authorize="yes" class="dcui-btn dcui-btn-orange" onclick="btn_update()"><i class="fa fa-reply"></i>更新数据</a>
            <a href="#" id="NF-createsysuser" authorize="yes" class="dcui-btn dcui-btn-orange" onclick="btn_createSysUser()"><i class="fa fa-user"></i>创建用户</a>
        </div>
        <script>$('#toolbar').authorizeButton()</script>
        <div class="dcui-search-area">
            关键字: <input class="easyui-textbox" style="width:110px" id="txt_keyword" placeholder="用户名称/手机号码">
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search">查询</a>
        </div>
    </div>

    <table id="dg" class="easyui-datagrid" style="width:100%;min-height:600px;height:100%;"></table>
</div>

<script>
    $(function () {
        gridList();
    })
    function gridList() {

        $('#dg').datagrid({
            url: "/DingTalkManage/Users/GetGridJson",
            toolbar: '#toolbar',
            hideColumn: "F_Id",
            autoRowHeight: false,
            nowrap: true,
            singleSelect: true,
            method: 'get',
            queryParams: {
                keyword: "",
            },
            columns: [[
                { field: 'UserId', hidden: true },
                { field: 'UserName', title: '员工名字', width: 150, align: 'center' },
                { field: 'JobNumber', title: '员工工号', width: 120, align: 'center' },
                { field: 'Position', title: '职位信息', width: 120, align: 'center' },
                { field: 'Mobile', title: '手机号码', width: 120, align: 'center' },
                { field: 'Email', title: '电子邮件', width: 140, align: 'center' },
                {
                    field: 'IsBoss', title: '老板', width: 60, align: 'center',
                    formatter: function (value, row, index) {
                        return value == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                {
                    field: 'IsLeaderInDepts', title: '主管', width: 60, align: 'center',
                    formatter: function (value, row, index) {
                        return value == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                {
                    field: 'IsAdmin', title: '管理员', width: 60, align: 'center',
                    formatter: function (value, row, index) {
                        return value == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                {
                    field: 'Active', title: '激活', width: 60, align: 'center',
                    formatter: function (value, row, index) {
                        return value == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                {
                    field: 'UpdateTime', title: '更新日期', width: 130, align: 'right',
                    formatter: function (value, row, index) {
                        if (value) {
                            return value;
                        }
                    }
                }

            ]]
        });

        $("#btn_search").click(function () {
            var queryJson = {
                keyword: $("#txt_keyword").val()
            }
            $('#dg').datagrid('load', queryJson);
        });

    }

    function btn_edit() {
        var selected = $('#dg').datagrid('getSelected');
        if (selected != null) {
            $.modalOpen({
                id: "Form",
                title: "修改用户",
                url: "/DingTalkManage/Users/Form?keyValue=" + selected.UserId,
                width: "450px",
                height: "380px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }

    function btn_details() {
        var selected = $('#dg').datagrid('getSelected');
        if (selected != null) {
            $.modalOpen({
                id: "Details",
                title: "查看信息",
                url: "/DingTalkManage/Users/Details?keyValue=" + selected.UserId,
                width: "450px",
                height: "500px",
                btn: null,
            });
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
    function btn_update() {
        $.submitPost({
            title: "确定要更新钉钉用户吗？",
            url: "/DingTalkManage/Users/UpdateDingTalkUser",
            success: function () {
                $("#dg").datagrid("reload");
            }
        })
    }

    function btn_sendMsg() {
        $.submitPost({
            title: "确定要发送信息吗？",
            url: "/DingTalkManage/Users/SendWorkMsg",
            param: { keyValue: $("#gridList").jqGridRowValue().UserId },
            success: function () {
                $("#dg").datagrid("reload");
            }
        })
    }
    function btn_sendRecord() {
        $.submitPost({
            title: "确定要发送任务吗？",
            url: "/DingTalkManage/Users/SendWrokRecord",
            param: { keyValue: $("#gridList").jqGridRowValue().UserId },
            success: function () {
                $("#dg").datagrid("reload");
            }
        })
    }
    function btn_createSysUser() {
        $.submitPost({
            title: "确定要为用户创建系统账号吗？",
            url: "/DingTalkManage/Users/CreateSysUser",
            param: { keyValue: $("#gridList").jqGridRowValue().UserId },
            success: function () {
                $("#dg").datagrid("reload");
            }
        })
    }
    function btn_createRemind() {
        $.submitPost({
            title: "确定要为用户创建日志提醒吗？",
            url: "/DingTalkManage/Users/CreateRemind",
            param: { keyValue: $("#gridList").jqGridRowValue().UserId },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
</script>
